package huawei;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main1 {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[][] mat = new int[n][2];

        int start = -1,end = -1;
        for(int i=0;i<n;i++){
            mat[i][0] = in.nextInt();
            mat[i][1] = in.nextInt();

            end = Math.max(end,mat[i][1]);
        }

        Arrays.sort(mat, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[0] - o2[0];
            }
        });
        start = mat[0][0];

        /*
            找出时间片的开始结束两端
            for 对于每段时间片，查看有几个任务需要占据,0-1,1-3,n-4;

            如何查看有几个任务需要占据呢？
         */

        //空载
        long res = end-start+1;
        // 对于每秒如果当前单任务，那么在此基础上+2，如果当前多任务，再+1并break
        for(int i = start;i<=end;i++){
            int state = 0;// 0 1 2
            for(int j = 0;j<n;j++){
                if(mat[j][0]<=i&&mat[j][1]>=i){
                    if(state == 0){
                        res+=2;
                        state = 1;
                    } else if (state == 1) {
                        res+=1;
                        state = 2;
                        continue;
                    }
                }
            }

        }

        System.out.println(res);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[][] mat = new int[n][2];
        long res = 0;

        int start = -1,end = -1;
        for(int i=0;i<n;i++){
            mat[i][0] = in.nextInt();
            mat[i][1] = in.nextInt();
            start = start == -1?mat[i][0]:Math.min(start,mat[i][0]);
            end = Math.max(end,mat[i][1]);
        }

        int len = end-start+1;
        int[] arr = new int[len];//start为第一个 表示当前秒需要的功耗 下标-start

        for(int i = 0;i<n;i++){
            int a = mat[i][0];
            int b = mat[i][1];

            for(int j = a;j<=b;j++){
                if(arr[j-start] == 0) arr[j-start] = 3;
                if(arr[j-start] == 3) arr[j-start] = 4;
            }
        }

        for(int i = 0;i<len;i++){
            if(arr[i] == 0) res+=1;
            if(arr[i] == 3) res+=3;
            else res+=4;
        }

        System.out.println(res);
    }
}
